package fr.utbm.gi.in56.user;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import fr.utbm.gi.in56.database.DatabaseServlet;
import fr.utbm.gi.in56.notification.NotificationType;

/**
 * Servlet implementation class LogoutServlet
 * 
 * @author Adrien Hoffer & Tarik Belabbas
 */
@WebServlet( "/LogoutServlet" )
public class LogoutServlet extends DatabaseServlet
{
	/**
	 * Version number associated to the serializable class.
	 */
	private static final long	serialVersionUID	= 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public LogoutServlet()
	{
		super();
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet( HttpServletRequest request,
			HttpServletResponse response ) throws ServletException, IOException
	{
		HttpSession session = request.getSession( true );
		session.removeAttribute( "currentSessionUser" ); //$NON-NLS-1$
		
		request.setAttribute( "notification", NotificationType.LOGOUT_SUCCESS ); //$NON-NLS-1$
		RequestDispatcher rd = request.getRequestDispatcher("notification.jsp"); //$NON-NLS-1$
		rd.forward( request, response );
		return;
	}

}
